import store from '@/store'

export function setOem() {
  return new Promise((resolve, reject) => {
    const host = location.host
    // case 'localhost:9527'
    let activeOem = 'default'
    switch (host) {
      case 'https://marketing-partner-test.fuhuiba.ltd':
        activeOem = 'oemActive'
        break
      // case 'sp.keyi365.com':
      //   activeOem = 'ky'
      //   break
      // case 'fws.changyoubao.com':
      //   activeOem = 'cyb'
      //   break
      // case 'sp.packertec.com':
      //   activeOem = 'ps'
      //   break
      // case 'sp.wlinkco.com':
      //   activeOem = 'wlinkco'
      //   break
      // case 'daili.anshanpay.com':
      //   activeOem = 'anshan'
      //   break
      // case 'sp.yinfei.wang':
      //   activeOem = 'yinfei'
      //   break
      // case 'sp.wistown.net':
      //   activeOem = 'wistown'
      //   break
    }
    const activeFavicon = `./static/oem/${activeOem}/favicon.ico`
    store.state.config.oemMap.activeOem = activeOem
    addFaviconLink(activeFavicon)
  })
}

function addFaviconLink(url) {
  const doc = document
  const link = doc.createElement('link')
  link.setAttribute('rel', 'shortcut icon')
  link.setAttribute('href', url)
  const heads = doc.getElementsByTagName('head')
  if (heads.length) {
    heads[0].appendChild(link)
  } else {
    doc.documentElement.appendChild(link)
  }
}
